<?php

namespace app\shop\controller;

use buildView\Actions;
use buildView\Grid;
use think\Controller;
use buildView\Form;
use app\shop\model\ShopGoodsCate;

/**
 * 商品分类
 * Class Cate
 * @package app\admin\controller
 */
class Cate extends Controller
{
    /**
     * 列表
     * @auth true
     * @menu true
     * @return string
     */
    public function index()
    {
        $grid = new Grid(new ShopGoodsCate);
        $grid->setTitle('商品分类');
        $grid->model()->where('pid','>',0)->order('sort asc,id desc');
        $grid->title('分类名称');
        $grid->status('是否显示')->switchs();
        $grid->create_at('创建时间');
        $grid->hideExportButton();
        $grid->setFromOpen();
        $grid->actions(function (Actions $action) {
            $action->hideDetail();
        });
        return $grid->view();
    }

    /**
     * 添加/编辑
     * @auth true
     * @menu true
     * @return string
     */
    public function form()
    {
        $cates = ShopGoodsCate::field('id,title,pid')->where('pid', 0)->column('title','id');
        // halt($cates);
        $form = new Form(new ShopGoodsCate);
        $form->text('title','分类名称')->required();
        $form->select('pid', '父级分类')->options($cates)->default(1);
        return $form->view();
    }


}
